//
//  WPReadingSearchBtn.m
//  wobingwoyi
//
//  Created by WGP on 16/7/28.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPReadingSearchBtn.h"

@implementation WPReadingSearchBtn

+(instancetype)btnWithImageName:(NSString *)imageName title:(NSString *)title
{
    WPReadingSearchBtn *btn  = [self buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = RGB_SAME(237);
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:13];
    
    [btn setTitleColor:RGB_SAME(153) forState:UIControlStateNormal];
    
    [btn.titleLabel sizeToFit];
    btn.titleLabel.textAlignment = NSTextAlignmentLeft;
    
    btn.layer.cornerRadius = 6*SCALE;
    btn.layer.masksToBounds = YES;
    return btn;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat imageW = 15*SCALE;
    CGFloat imageH = imageW;
    CGFloat imageX = 10*KWIDTH_SCALE;
    CGFloat imageY = (self.bounds.size.height-imageH)*0.5;
    
    self.imageView.frame = CGRectMake(imageX, imageY, imageW, imageH);
    
    CGFloat titleLabelW = self.titleLabel.bounds.size.width;
    CGFloat titleLabelH = self.titleLabel.bounds.size.height;
    CGFloat titleLabelX = CGRectGetMaxX(self.imageView.frame)+7*KWIDTH_SCALE;
    CGFloat titleLabelY = (self.bounds.size.height-titleLabelH)*0.5;
    
    self.titleLabel.frame = CGRectMake(titleLabelX, titleLabelY, titleLabelW, titleLabelH);
}

@end
